package net.tinyos.tools;

import net.tinyos.message.MoteIF;
import net.tinyos.packet.BuildSource;
import net.tinyos.packet.PhoenixSource;
import net.tinyos.util.PrintStreamMessenger;
import edu.zju.DBPrintfClient;

public class ListenLuoSensor implements Runnable{
	public String mainfunction(String args1, String args2) {
		String str = args1 + args2;
		int USBnum = 0;

		String source = null;
		if (!args1.equals("-comm")) {
			// usage();
			System.exit(1);
		}
		source = args2;
		if (source.charAt(19) != ':') {
			USBnum += source.charAt(19) - '0';
			USBnum += (source.charAt(18) - '0') * 10;
		} else {
			USBnum = source.charAt(18) - '0';
		}

		PhoenixSource phoenix = null;
		if (source == null) {
			phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
		} else {
			phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
		}
		// System.out.print(phoenix);
		MoteIF mif = new MoteIF(phoenix);

		DBPrintfClient client = new DBPrintfClient(mif, USBnum);
		return str + "*" + USBnum;
	}

	public static void main(String[] args) {
		ListenLuoSensor t = new ListenLuoSensor();

		String str = t.mainfunction("-comm", "serial@/dev/ttyUSB0:telosb");
		System.out.println("WSN~~~" + str);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
}
